package com.example.dllo.my36kr.news.newsecond.window;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.tools.NetTool;

/**
 * Created by dllo on 16/8/24.
 */
public class WindowAdapter extends BaseAdapter {
    Context mContext;
    WindowBean bean;
    private final NetTool mNetTool;

    public WindowAdapter(Context mContext) {
        this.mContext = mContext;
        mNetTool = new NetTool();
    }

    public void setBean(WindowBean bean) {
        this.bean = bean;
    }

    @Override
    public int getCount() {
        return bean != null ?bean.getData().getLatestArticle().size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        WindowViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.window_second_item,null);
            holder = new WindowViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (WindowViewHolder) convertView.getTag();
        }
        holder.titleTv.setText(bean.getData().getLatestArticle().get(position).getTitle());
        mNetTool.getImage(bean.getData().getLatestArticle().get(position).getFeatureImg(),holder.featureImgIv);

        return convertView;
    }
    public class WindowViewHolder{
        ImageView featureImgIv;
        TextView titleTv;
        public WindowViewHolder(View view) {
            featureImgIv = (ImageView) view.findViewById(R.id.iv_window_second_featureImg);
            titleTv = (TextView) view.findViewById(R.id.tv_window_second_title);
        }
    }
}
